<template>
  <div>
    <mini-head :title="$route.name" />
    <van-address-edit
      :area-list="areaList"
      show-set-default
      show-postal
      tel-maxlength="11"
      area-placeholder
      @save="onSave"
      @change-area="cheak"
    />
  </div>
</template>

<script>
import { areaList } from '@vant/area-data'
import { addLinkman } from '_api'
import { Toast } from 'vant'
import MiniHead from '../../components/MiniHead.vue'
import { gettoken } from '../../utils'
export default {
  components: { MiniHead },
  data () {
    return {
      areaList,
      areaInfo: '', // 省市区名字
      conner: {
        linkMan: '',
        mobile: '',
        address: '',
        code: '',
        cityId: '', // 市编码
        provinceId: '', // 省编码
        districtId: '', // 区编码
        isDefault: false
      }
    }
  },
  methods: {
    cheak (e) {
      this.conner.provinceId = e[0].code
      this.conner.cityId = e[1].code
      this.conner.districtId = e[2].code
    },
    onSave (e) {
      console.log(e)
      this.conner.address = e.addressDetail
      this.conner.linkMan = e.name
      this.conner.mobile = e.tel
      this.conner.code = e.postalCode
      this.conner.isDefault = e.isDefault
      this.areaInfo = e.province + e.city + e.county
      addLinkman({
        ...this.conner,
        token: gettoken()
      }).then((res) => {
        if (res.data.code === 0) {
          console.log(res)
          Toast('添加成功')
          this.$router.go(-1)
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped></style>
